<template>
    <div>
        <mi-upload :uploadUrl="uploadUrl"
                   :limit="1"
                   :params="params"
                   type="file"
                   @confirm="confirm">
            <div>
                <el-button type="primary">上传</el-button>
            </div>
        </mi-upload>
        <el-tooltip :content="modelValue" v-if="modelValue!=''">
            <el-button type="success" text size="small" >
                <div class="d_flex flex_jc_sb">
                    <span class="flex_1">{{modelValue}}</span>
                    <el-icon class="el-icon--right" @click="remove()"><Close /></el-icon>
                </div>
            </el-button>
        </el-tooltip>
    </div>
</template>

<script setup lang="ts">

const props = withDefaults(defineProps<{
    modelValue?: string,
    uploadUrl?: string,
    params?: Record<string, any>,
}>(),{
    uploadUrl:import.meta.env.VITE_APP_UPLOAD_FILE_URL
})

const emits = defineEmits(['update:modelValue', 'onChange'])


const remove = () => {
    emits("update:modelValue", '')
}

const confirm = (files: any[]) => {
    emits('update:modelValue', files[0].path)
}

</script>

<style scoped>
</style>
